package com.supinfo.food.services;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

import com.supinfo.food.activity.CuisineActivity;
import com.supinfo.food.define.Define;

import android.os.AsyncTask;
import android.util.Log;

/**
 * WS for state update
 * @author Keitaro
 *
 */
public class UpdateStates extends AsyncTask<String, Void, Void> {

	private static final String NAMESPACE = "android.services.food.supinfo.com";
	private static final String URL = Define.IP + "/services/OrderWSAndroid?wsdl";
	private static final String SOAP_ACTION = "OrderWSAndroid";
	private static final String METHOD_ACTION = "update";
	private CuisineActivity context;
	
	public UpdateStates(CuisineActivity context) {
		this.context = context;
	}
	
	@Override
	protected void onPreExecute() {
	}
	
	@Override
	protected Void doInBackground(String... params) {
		try
	    {
	    	SoapObject request = new SoapObject(NAMESPACE, METHOD_ACTION);
	    	SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	    	request.addProperty("orderParam", params[0]);
	    	envelop.setOutputSoapObject(request);
	    	AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
	    	androidHttpTransport.call(SOAP_ACTION, envelop);
	    } catch (Exception e)
	    {
	    	Log.e("updateStates", "", e);
	    }
		return null;
	}
	
	@Override
	protected void onPostExecute(Void result) {
		context.stopAlert();
		context.startHandler();
	}
}
